package com.lk.springboot.service.impl;

import com.lk.springboot.dao.UserMapper;
import com.lk.springboot.service.PidUtilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author lk
 * @date 2020/2/4 0004 21:37
 */
@Service
public class PidUtilServiceImpl implements PidUtilService {
    @Autowired
    UserMapper userMapper;

    public List getActiveRandomPid(String u_id, int n) {
        int number = 0;
        List<String> pidList = userMapper.getPidFromActive(u_id, 1);
        ArrayList<String> arrayList = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < n; i++) {
            number = random.nextInt(pidList.size());
            arrayList.add(pidList.get(number));
        }
        return arrayList;
    }

    public List getNoActiveRandomPid(String u_id, int n) {
        final int R = 50;//获得未激活站点的概率
        int number = 0;
        int pr = 0;
        Random random = new Random();
        List<String> pidListok = userMapper.getPidFromActive(u_id, 1);
        List<String> pidListno = userMapper.getPidFromActive(u_id, 0);
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            pr = (int) (Math.random() * 100);
            if (pr < R) {
                number = random.nextInt(pidListno.size());
                arrayList.add(pidListno.get(number));
            } else {
                number = random.nextInt(pidListok.size());
                arrayList.add(pidListok.get(number));
            }
        }
        return arrayList;
    }

}
